package com.onlyoffice.demo.findproblem.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.onlyoffice.demo.findproblem.domain.GameLevel;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface GameLevelMapper extends BaseMapper<GameLevel> {

    /**
     * 查询启用状态的关卡列表
     */
    @Select("SELECT * FROM game_level WHERE status = #{status}")
    List<GameLevel> selectByStatus(@Param("status") Integer status);

    /**
     * 根据难度查询关卡
     */
    @Select("SELECT * FROM game_level WHERE difficulty = #{difficulty} AND status = 1")
    List<GameLevel> selectByDifficulty(@Param("difficulty") Integer difficulty);

    /**
     * 查询关卡详情包含错误点
     */
    @Select("SELECT gl.*, es.id as spot_id, es.x_coordinate, es.y_coordinate, es.radius, es.description as spot_description " +
            "FROM game_level gl LEFT JOIN error_spot es ON gl.id = es.level_id " +
            "WHERE gl.id = #{levelId}")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "errorSpots", column = "id",
                    many = @Many(select = "com.example.spotgame.mapper.ErrorSpotMapper.selectByLevelId"))
    })
    GameLevel selectLevelWithSpots(@Param("levelId") Long levelId);
}
